package docs.cvs.test;

import docs.cvs.HelloSpring;
import docs.cvs.dao.impl.Printer;
import docs.cvs.pojo.User;
import docs.cvs.service.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {
    @Test
    public void testHelloSpring(){
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "applicationContext.xml"
        );
        HelloSpring helloSpring = (HelloSpring) context.getBean("helloSpring");
        helloSpring.print();
    }
    @Test
    public void printerTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 通过Printer bean的id来获取Printer实例
        
        Printer printer = (Printer) context.getBean("printer");
        String content = "轻灵..轻灵的鼠标一点,神奇的世界出现。双手..把双手放在胸前"
                + ",敲打出美丽的画卷。轻灵..轻灵的鼠标一点,神奇的世界出现。双手..把双"
                + "手放在胸前,敲打出美丽的画卷。是谁让IT生活多彩绚烂,青鸟在我们身边"
                + "纵然是IT时代风云变幻,青鸟青鸟与我们相伴。飞翔吧青鸟,将知识在神州"
                + "大地撒遍;飞翔吧青鸟,让教育改变我们的生活。是你帮助了我们实现了心愿"
                + "又是你让我们的世界变成无限。因为有你,地更广阔,天更蓝";
        printer.print(content);
    }
    @Test
    public void aopTest(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserServiceImpl service = (UserServiceImpl) ctx.getBean("userService");
        User user = new User();
        user.setId(1);
        user.setUserRoleName("test");
        user.setPassword("123456");
        user.setEmail("test@xxx.com");
        service.save(user);
    }
}
